登录 白背景

1103. 分糖果 II

https://leetcode.cn/problems/distribute-candies-to-people/

  • 提交时间:2023-03-07 11:59:06
  • 执行用时:4 ms, 在所有 Go 提交中击败了6.90%的用户
  • 内存消耗:1.9 MB, 在所有 Go 提交中击败了31.03%的用户
  • 通过测试用例:27 / 27

func distributeCandies(candies int, num_people int) []int {
    ret := make([]int, num_people)
    plus := 0
    for i := 0; candies != 0; i++ {
        if i == num_people {
            i = 0
        }
        plus += 1
        if plus <= candies {
            candies -= plus
            ret[i] += plus
            continue
        }
        ret[i] += candies
        candies = 0
        break
    }
    return ret
}